package com.quanyan.user.service.impl;

import com.quanyan.api.APIRequest;
import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.AssetsPayReceive;
import com.quanyan.api.enums.AssetsType;
import com.quanyan.assets.request.ReqCoupon;
import com.quanyan.assets.request.ReqUserAccumulateModify;
import com.quanyan.assets.response.RespUserAccumulateModify;
import com.quanyan.assets.service.CouponService;
import com.quanyan.assets.service.UserAssetsService;
import com.quanyan.common.constants.Constants;
import com.quanyan.common.enums.CommonParameterEnum;
import com.quanyan.common.enums.LarkAppIdEnum;
import com.quanyan.common.utils.DateUtils;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.user.cache.MyRedisTemplate;
import com.quanyan.user.constants.UserConstants;
import com.quanyan.user.mapper.*;
import com.quanyan.user.model.db.*;
import com.quanyan.user.model.vo.request.ReqUserThirdAccount;
import com.quanyan.user.model.vo.response.RespBatchUserInterest;
import com.quanyan.user.model.vo.response.RespUserInterest;
import com.quanyan.user.model.vo.response.RespUserThirdAccount;
import com.quanyan.user.model.vo.response.UserIcon;
import com.quanyan.user.model.vo.response.admin.RespUser;
import com.quanyan.user.service.*;
import com.quanyan.user.utils.LarkCodeUtil;
import main.java.com.UpYun;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;

/**
 * Created by zhang on 16/7/18.
 */
@Service("userToCService")
public class UserToCServiceImpl extends UserBaseServiceImpl implements UserToCService {

    private final static Logger logger = LoggerFactory.getLogger(UserToCServiceImpl.class);

    //upYun运行前先设置好以下三个参数
    private static final String BUCKET_NAME = "quncao";
    private static final String OPERATOR_NAME = "quncao";
    private static final String OPERATOR_PWD = "quncao888";

    @Autowired
    private TbUserInterestMapper userInterestMapper;
    @Autowired
    private TbLevelMapper levelMapper;
    @Autowired
    private TbLevelParamMapper levelParamMapper;
    @Autowired
    private TbCommonParameterMapper commonParameterMapper;
    @Autowired
    private TbUserMapper userMapper;
    @Autowired
    private UserInterestService userInterestService;
    @Autowired
    private UserExtService userExtService;
    @Autowired
    private UserMedalService userMedalService;
    @Autowired
    private UserAdminMapper userAdminMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private MyRedisTemplate myRedisTemplate;
    @Autowired
    private HttpClientService httpClientService;
    @Autowired
    private CouponService couponService;
    @Autowired
    private OperationActivityMapper operationActivityMapper;
    @Autowired
    private UserAssetsService userAssetsService;
    @Autowired
    private TbAppPromotionChannelMapper appPromotionChannelMapper;
    @Autowired
    private TbUserThirdAccountMapper userThirdAccountMapper;


    /**
     * 批量获取用户兴趣
     * @param list
     * @return
     */
    @Override
    public List<RespBatchUserInterest> batchQueryUserInterestList(List list) {
        List<RespBatchUserInterest> respBatchUserInterestList = new ArrayList<>();
        if (list.isEmpty()) {
            return respBatchUserInterestList;
        }else{
            for (Object i : list) {
                List<TbUserInterest> userInterestList = this.getUserInterestList((int)i);
                if (userInterestList.isEmpty()) {

                }else{
                    RespBatchUserInterest respBatchUserInterest = new RespBatchUserInterest();
                    respBatchUserInterest.setUid((int)i);
                    List<RespUserInterest> respUserInterestList = new ArrayList<>();
                    if (!userInterestList.isEmpty()) {
                        RespUserInterest respUserInterest;
                        for (TbUserInterest tbUserInterest : userInterestList) {
                            respUserInterest = new RespUserInterest();
                            respUserInterest.setInterestId(tbUserInterest.getInterestId());
                            respUserInterestList.add(respUserInterest);
                        }
                    }
                    respBatchUserInterest.setRespUserInterestList(respUserInterestList);
                    respBatchUserInterestList.add(respBatchUserInterest);
                }
            }
        }
        return respBatchUserInterestList;
    }

    /**
     * 新用户初始化
     * @param map
     */
    @Override
    public void initUserInfo(Map map) {
        Integer currentUid = 0;
        try {
            currentUid = (Integer) map.get("currentUid");
            logger.info("开始用户初始化 uid：{}",currentUid);

            /**----------------------------------------初始化用户勋章开始--------------------------------------**/
            List<TbUserMedalRelation> userMedalRelationList = userMedalService.getUserMedalRelationList(currentUid);

            if (userMedalRelationList.isEmpty()) {
                userMedalService.initUserMedalList(currentUid);
                logger.info("用户勋章初始化完成 uid：{}",currentUid);
            }
            /**----------------------------------------初始化用户勋章结束--------------------------------------**/

            /**----------------------------------------初始化用户等级开始--------------------------------------**/
            List<TbLevel> levelList = this.getLevelList(currentUid, Constants.SystemLevelType.USER_XP_TYPE);
            if (levelList.isEmpty()) {
                List<TbLevelParam> levelParamList = this.getLevelParamList(1, 1);
                TbLevel level = new TbLevel();
                level.setType(Constants.SystemLevelType.USER_XP_TYPE.byteValue());
                level.setXp(0);
                level.setLevel(0);
                level.setCommonId(currentUid);
                if (levelParamList.isEmpty()) {
                    level.setNextLevelXp(0);
                }else{
                    level.setNextLevelXp(levelParamList.get(0).getXp());
                }
                this.insertLevel(level);
                logger.info("用户等级初始化完成 uid：{}",currentUid);
            }
            /**----------------------------------------初始化用户等级结束--------------------------------------**/

            /**----------------------------------------初始化用户拓展信息开始--------------------------------------**/
            //初始化用户背景图片
            List<TbCommonParameter> commonParameterList = this.getCommonParameterList(CommonParameterEnum.USER_SYSTEM_BG.getCode());
            int k=0;
            if (!commonParameterList.isEmpty()) {
                k = new Random().nextInt(commonParameterList.size());
            }
            TbUserExt userExt = new TbUserExt();
            userExt.setUid(currentUid);
            userExt.setBgUrl(commonParameterList.get(k).getParameterValue());
            userExtService.updateUserExt(userExt);
            logger.info("个人背景图片初始化成功：【{}】",currentUid);
            /**----------------------------------------初始化用户拓展信息结束--------------------------------------**/

            /**----------------------------------------初始化用户兴趣开始--------------------------------------**/
            TbUser user = this.getUser(currentUid);
            if (user != null) {
                String dsn = user.getDsn();
                if (!StringUtil.isBlankOrNull(dsn)) {
                    List<TbUserInterest> userInterestList = this.userInterestService.getUserInterestList(UserConstants.USER_VISITOR,
                            currentUid,
                            dsn,
                            UserConstants.USER_INTEREST_IS_OBTAIN);
                    if (userInterestList.isEmpty()) {
                        this.userInterestService.batchInsertUserInterest(currentUid,dsn,UserConstants.USER_REGISTER);
                    }else{
                        for (TbUserInterest userInterest : userInterestList) {
                            userInterest.setUid(currentUid);
                            this.userInterestService.updateUserInterest(
                                    userInterest,
                                    null,
                                    UserConstants.USER_VISITOR,
                                    null,
                                    dsn,
                                    UserConstants.USER_INTEREST_IS_REGISTER);
                        }
                    }

                }else{
                    this.userInterestService.batchInsertUserInterest(currentUid,dsn,UserConstants.USER_REGISTER);
                }
            }
            /**----------------------------------------初始化用户兴趣结束--------------------------------------**/

            if(user != null){
                //第三方注册用户，用户图片上传到upyun
                uploadIconToUpyun(user);

                // 新注册用户发放优惠券
                issuseCoupon(user);

                //发放88个鸟蛋（运营活动）
                //issuseBirdEggs(user);
            }
        }catch (Exception e){
            logger.error("用户初始化失败 uid：{},异常信息为：{}",currentUid,e);
        }
    }

    private void issuseBirdEggs(TbUser user) {
        Byte sourceChannel = user.getSourceChannel();
        Integer uid = user.getId();
        String nickName = user.getNickName();
        String mobile = user.getMobile();
        if (sourceChannel != null && sourceChannel == 4) {
            List<TbOperationActivity> operationActivities = operationActivityMapper.getOperationActivityList((byte) 1);
            if (operationActivities != null && operationActivities.size() > 0) {
                Date nowDate = new Date();
                for (TbOperationActivity operationActivity : operationActivities) {
                    Date activityStartTime = operationActivity.getActivityStartTime();
                    Date activityEndTime = operationActivity.getActivityEndTime();
                    if (activityStartTime != null && activityEndTime != null) {
                        if (nowDate.compareTo(DateUtils.dayBegin(activityStartTime)) >= 0 && nowDate.compareTo(DateUtils.dayEnd(activityEndTime)) <= 0) {
                            APIRequest<ReqUserAccumulateModify> apiRequest = new APIRequest<>();
                            ReqUserAccumulateModify reqUserAccumulateModify = new ReqUserAccumulateModify();
                            reqUserAccumulateModify.setUid(uid);
                            if (StringUtils.isNotBlank(nickName))
                                reqUserAccumulateModify.setReceiver(nickName);
                            else
                                reqUserAccumulateModify.setReceiver(mobile);
                            reqUserAccumulateModify.setAssetsType((byte) AssetsType.ASSETS_EGGS.getId().intValue());
                            reqUserAccumulateModify.setSystemCode(Constants.USER_CENTER_SYSTEM_CODE);
                            reqUserAccumulateModify.setBusinessCode(Constants.USER_NOVICE_ADD_EGGS_CODE);
                            reqUserAccumulateModify.setPayReceive(AssetsPayReceive.SYSTEM.getName());
                            reqUserAccumulateModify.setInfo("新手礼包");
                            apiRequest.setData(reqUserAccumulateModify);
                            try {
                                APIResponse<RespUserAccumulateModify> apiResponse = userAssetsService.modifyAccumulate(apiRequest);
                                if (!apiResponse.isRet())
                                    logger.info("失败信息：{}",apiResponse.getErrmsg());
                            } catch (Exception e) {
                                logger.error("新注册用户发放88个鸟蛋（运营活动）失败,异常：{}", e.getMessage());
                            }
                        }
                    }
                }
            }
        }
    }

    private void issuseCoupon(TbUser user) {
        String mobile = user.getMobile();
        Integer uid = user.getId();
        if (mobile != null && uid != null) {
            APIRequest<ReqCoupon> apiRequest = new APIRequest<>();
            ReqCoupon reqCoupon = new ReqCoupon();
            reqCoupon.setUid(uid);
            reqCoupon.setMobile(mobile);
            apiRequest.setData(reqCoupon);
            try {
                couponService.associateUsers(apiRequest);
            } catch (Exception e) {
                logger.error("用户注册绑定优惠券失败");
            }
        }
    }


    //第三方注册用户，用户图片上传到upyun
    private void uploadIconToUpyun(TbUser user) {
        if (user.getRegType() != null && user.getRegType() != 0) { //判断是否是第三方注册
            String icon = user.getIcon();
            Integer uid = user.getId();
            if (StringUtil.isNotBlank(icon)) {
                InputStream inputStream = null;
                ByteArrayOutputStream swapStream = null;
                try {
                    String urlSplit[] = icon.split("/");
                    if (urlSplit.length < 3) {
                        return;
                    }
                    String fileLocation = "/user/icon/" + uid.toString() + urlSplit[urlSplit.length - 2];

                    URL url = new URL(icon);
                    inputStream = url.openStream();
                    swapStream = new ByteArrayOutputStream();
                    byte[] buff = new byte[1024];
                    int rc = 0;
                    while ((rc = inputStream.read(buff, 0, 1024)) > 0) {
                        swapStream.write(buff, 0, rc);
                    }
                    byte[] bytes = swapStream.toByteArray();

                    UpYun upYun = new UpYun(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
                    upYun.setTimeout(60); //设置超时时间
                    upYun.setDebug(false); // 设置是否开启debug模式，默认不开启
                    boolean result = upYun.writeFile(fileLocation, bytes, true); //上传图片到upyun

                    if (result) {
                        //更新icon和缓存
                        icon = "http://" + BUCKET_NAME + ".b0.upaiyun.com" + fileLocation; //获取回调地址
                        user.setIcon(icon);
                        String userKey = UserConstants.getUserRedisKey(uid);
                        userMapper.updateByPrimaryKeySelective(user);
                        myRedisTemplate.set(userKey, userMapper.selectByPrimaryKey(uid), 7);
                        String keyDetail = UserConstants.getUserDetailRedisKey(uid);
                        myRedisTemplate.set(keyDetail, userInfoMapper.findUserInfoDetail(uid), 7);
                        httpClientService.updateSetting(uid, null, 1, 1);
                    }

                } catch (Exception e) {
                    logger.error("获取第三方用户注册图片失败!");
                } finally {
                    try {
                        if (swapStream != null)
                            swapStream.close();
                        if (inputStream != null)
                            inputStream.close();
                    } catch (IOException e) {
                        logger.error("IO流关闭失败！");
                    }
                }
            }

        }
    }


    /**
     * 获取用户等级信息
     * @param uid
     * @param type
     * @return
     */
    private List<TbLevel> getLevelList(Integer uid,Integer type){
        TbLevelExample example = new TbLevelExample();
        example.createCriteria().andIsDeleteEqualTo(Constants.IS_DELETE_FALSE).andCommonIdEqualTo(uid).andTypeEqualTo(type.byteValue());
        List<TbLevel> levelList = this.levelMapper.selectByExample(example);
        return levelList;
    }

    /**
     * 获取等级参数信息
     * @param type
     * @param level
     * @return
     */
    private List<TbLevelParam> getLevelParamList(Integer type,Integer level){
        TbLevelParamExample example = new TbLevelParamExample();
        example.createCriteria().andIsDeleteEqualTo(Constants.IS_DELETE_FALSE).andTypeEqualTo(type.byteValue()).andLevelEqualTo(level);
        List<TbLevelParam> levelParamList = this.levelParamMapper.selectByExample(example);
        return levelParamList;
    }

    /**
     * 插入用户等级信息
     * @param level
     * @return
     */
    private int insertLevel(TbLevel level){
        int n = this.levelMapper.insertSelective(level);
        return n;
    }


    /**
     * 获取系统公共配置参数
     * @param parameterKey
     * @return
     */
    private List<TbCommonParameter> getCommonParameterList(String parameterKey){
        TbCommonParameterExample example = new TbCommonParameterExample();
        TbCommonParameterExample.Criteria criteria = example.createCriteria();
        criteria.andIsDeleteEqualTo(Constants.IS_DELETE_FALSE);
        criteria.andParameterKeyEqualTo(parameterKey);
        List<TbCommonParameter> commonParameterList = this.commonParameterMapper.selectByExample(example);
        return commonParameterList;
    }

    /**
     * 获取个人信息
     * @param uid
     * @return
     */
    private TbUser getUser(Integer uid){
        TbUser user = this.userMapper.selectByPrimaryKey(uid);
        return user;
    }

    /**
     * 更新运动达人信息
     * @param uid
     * @param type
     * @return
     */
    @Override
    public Integer updateTalent(Integer uid, Integer type) {
        TbUserExt userExt = new TbUserExt();
        userExt.setUid(uid);
        if (type.equals(UserConstants.IS_BIDS_VERIFY)) {    //竞拍认证
            userExt.setIsBidsVerify(Constants.BYTE_ONE);
        } else if (type.equals(UserConstants.IS_BUYOUT_VERIFY)) {   //一口价认证
            userExt.setIsBuyoutVerify(1);
        } else if (type.equals(UserConstants.IS_BIDS_AND_BUYOUT_VERIFY)) {      //竞拍、一口价双重认证
            userExt.setIsBidsVerify(Constants.BYTE_ONE);
            userExt.setIsBuyoutVerify(1);
        } else if (type.equals(UserConstants.CANCEL_BIDS_VERIFY)) {     //取消竞拍认证
            userExt.setIsBidsVerify(Constants.BYTE_ZERO);
        } else if (type.equals(UserConstants.CANCEL_BUYOUT_VERIFY)) {       //取消一口价认证
            userExt.setIsBuyoutVerify(0);
        } else if (type.equals(UserConstants.CANCEL_BIDS_AND_BUYOUT_VERIFY)) {      //取消竞拍、一口价双重认证
            userExt.setIsBidsVerify(Constants.BYTE_ZERO);
            userExt.setIsBuyoutVerify(0);
        }
        boolean flag = userExtService.updateUserExt(userExt);
        if (flag == true) {
            return 1;
        } else {
            return 0;
        }
    }
    /**
     * 初始化昵称为空的用户
     * @return
     */
    @Override
    public List<Integer> initUserNickName() {
        List<RespUser> userList = userAdminMapper.getNickNameIsNullList();
        List<Integer> uidList = new ArrayList<>();

        if (!userList.isEmpty()) {
            Map map;
            for (RespUser user : userList) {
                map = new HashMap();
                Integer uid = user.getId();
                String nickName = LarkCodeUtil.generateDefaultNickName(user.getMobile());
                map.put("uid",uid);
                map.put("nickName",nickName);
                userAdminMapper.updateNullNickName(map);
                uidList.add(uid);
            }
        }
        return uidList;
    }

    /**
     * 更新用户year字段
     * @return
     */
    @Override
    public List<Integer> updateUserYear() {
        List<Integer> result = new ArrayList<>();
        List<RespUser> userList = userAdminMapper.getUserYearIsZero();
        TbUser user;
        for (RespUser respUser : userList) {
            user = new TbUser();
            Date birthday = respUser.getBirthday();
            user.setId(respUser.getId());
            user.setYear(DateUtils.getYear(birthday.getTime()));
            userMapper.updateByPrimaryKeySelective(user);
            result.add(respUser.getId());
        }
        return result;
    }

    /**
     * 获取用户兴趣列表
     * @param uid
     * @return
     */
    private List<TbUserInterest> getUserInterestList(int uid){
        TbUserInterestExample example = new TbUserInterestExample();
        TbUserInterestExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(uid);
        criteria.andIsDeleteEqualTo(Constants.IS_DELETE_FALSE);
        criteria.andIsObtainEqualTo(Constants.BYTE_ONE);
        List<TbUserInterest> list = this.userInterestMapper.selectByExample(example);
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void disposeUserIcon(Integer pageNum, Integer pageSize, String keyWord) {
        List<UserIcon> userIcons = userInfoMapper.getIcon(pageNum,pageSize,keyWord);
        TbUser user = new TbUser();
        for (UserIcon userIcon :userIcons ) {
            Integer uid = userIcon.getUid();
            String icon = userIcon.getIcon();
            InputStream inputStream = null;
            ByteArrayOutputStream swapStream = null;
            try {
                String urlSplit[] = icon.split("/");
                if (urlSplit.length < 3) {
                    continue;
                }
                String fileLocation = "/user/icon/" + uid.toString() + urlSplit[urlSplit.length - 2];

                URL url = new URL(icon);
                inputStream = url.openStream();
                if (inputStream == null){
                    continue;
                }
                swapStream = new ByteArrayOutputStream();
                byte[] buff = new byte[1024];
                int rc = 0;
                while ((rc = inputStream.read(buff, 0, 1024)) > 0) {
                    swapStream.write(buff, 0, rc);
                }
                byte[] bytes = swapStream.toByteArray();

                UpYun upYun = new UpYun(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
                upYun.setTimeout(60); //设置超时时间
                upYun.setDebug(false); // 设置是否开启debug模式，默认不开启
                boolean result = upYun.writeFile(fileLocation, bytes, true); //上传图片到upyun

                if (result) {
                    //更新icon和缓存
                    icon = "http://" + BUCKET_NAME + ".b0.upaiyun.com" + fileLocation; //获取回调地址
                    user.setId(uid);
                    user.setIcon(icon);
                    String userKey = UserConstants.getUserRedisKey(uid);
                    userMapper.updateByPrimaryKeySelective(user);
                    myRedisTemplate.set(userKey, userMapper.selectByPrimaryKey(uid), 7);
                    String keyDetail = UserConstants.getUserDetailRedisKey(uid);
                    myRedisTemplate.set(keyDetail, userInfoMapper.findUserInfoDetail(uid), 7);
                    httpClientService.updateSetting(uid, null, 1, 1);
                }

            } catch (Exception e) {
                logger.error("获取第三方用户注册图片失败!");
            } finally {
                try {
                    if (swapStream != null)
                        swapStream.close();
                    if (inputStream != null)
                        inputStream.close();
                } catch (IOException e) {
                    logger.error("IO流关闭失败！");
                }
            }
        }

    }

    /**
     * 更新用户注册时间
     * @return
     */
    @Override
    public List<Integer> updateUserRegTime() {
        List<RespUser> userList = userAdminMapper.getUserRegTimeIsNull();
        TbUser user;
        List<Integer> uidList = new ArrayList<>();
        for (RespUser respUser : userList) {
            if (respUser.getCreateTime() != null) {
                user = new TbUser();
                user.setRegTime(respUser.getCreateTime());
                user.setId(respUser.getId());
                int n = userMapper.updateByPrimaryKeySelective(user);
                if (n>0) {
                    uidList.add(respUser.getId());
                }
            }
        }
        return uidList;
    }

    /**
     * 添加有米推广渠道
     * @param mac
     * @param ifa
     * @param callbackUrl
     */
    @Override
    public int addYoumiPromotion(String mac, String ifa, String callbackUrl) {
        TbAppPromotionChannel appPromotionChannel = new TbAppPromotionChannel();
        appPromotionChannel.setCallbackUrl(callbackUrl);
        appPromotionChannel.setIfa(ifa);
        appPromotionChannel.setMac(mac);
        int n = appPromotionChannelMapper.insertSelective(appPromotionChannel);
        return n;
    }

    /**
     * 获取用户第三方绑定列表
     * @param reqUserThirdAccount
     * @return
     */
    @Override
    public APIResponse<List<RespUserThirdAccount>> getUserThirdAccountList(ReqUserThirdAccount reqUserThirdAccount) {
        int uid = reqUserThirdAccount.getUid();
        int type = reqUserThirdAccount.getType();
        TbUserThirdAccountExample example = new TbUserThirdAccountExample();
        TbUserThirdAccountExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(uid);
        if (type == UserConstants.WECHAT_TYPE) {
            criteria.andTypeEqualTo(UserConstants.WECHAT_TYPE);
        }
        criteria.andIsDeleteEqualTo(Constants.IS_DELETE_FALSE);
        List<TbUserThirdAccount> userThirdAccountList = userThirdAccountMapper.selectByExample(example);
        List<RespUserThirdAccount> respUserThirdAccountList = new ArrayList<>();
        for (TbUserThirdAccount userThirdAccount : userThirdAccountList) {
            respUserThirdAccountList.add(new RespUserThirdAccount(userThirdAccount));
        }
        return APIResponse.returnSuccess(respUserThirdAccountList);
    }

    /**
     * 初始化用户微信绑定
     * @return
     */
    @Override
    public List<Integer> initUserWechat() {
        List<RespUser> respUserList = userAdminMapper.getUserWechatBindingList();
        List<Integer> userList = new ArrayList<>();
        TbUserThirdAccount userThirdAccount ;
        for (RespUser respUser : respUserList) {
            userThirdAccount = new TbUserThirdAccount();
            userThirdAccount.setThirdGender(respUser.getGender());
            if (respUser.getWeixinAppIconUrl() != null) {
                userThirdAccount.setThirdIcon(respUser.getWeixinAppIconUrl());
            } else {
                userThirdAccount.setThirdIcon("");
            }
            userThirdAccount.setType(UserConstants.WECHAT_TYPE);
            userThirdAccount.setUnionId(respUser.getWeixinUnionid());
            userThirdAccount.setOpenId(respUser.getWeixinAppOpenid());
            if (StringUtils.isNotBlank(respUser.getWeixinNickname())) {
                userThirdAccount.setThirdNickname(respUser.getWeixinNickname());
            } else {
                userThirdAccount.setThirdNickname("");
            }
            userThirdAccount.setLarkAppId(LarkAppIdEnum.LARK_APP_C.getId());
            userThirdAccount.setUid(respUser.getId());
            insertUserThirdAccount(userThirdAccount);
            userList.add(respUser.getId());
        }
        return userList;
    }
}
